package com.homework.util;


import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.sql.Connection;
import java.util.Properties;

/**
 * @author: XiangHu
 * @date: 2025年02月25日 14:57
 * @describe:
 */
public class DataSourceUtils
{
    private static DataSource dataSource;
  static {
      Properties properties = new Properties();
      try {
          properties.load(DataSourceUtils.class.getClassLoader().getResourceAsStream("druid.properties"));
          dataSource = DruidDataSourceFactory.createDataSource(properties);
      }catch (Exception e)
      {
          throw new RuntimeException(e);
      }
  }
    public static Connection getConnection() {
        if(dataSource !=null) {
            try {
                return dataSource.getConnection();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        return null;
    }
}
